package pro.cherish.knowledgemqrabbitmq.lazy;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 创建人：cherish
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2019-12-03 cherish 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：MQReceiver
 * @Description 功能说明：消费者
 * <p>
 * TODO
 * </p>
 * **********************************************************************
 * @date 创建日期： 2019-12-03 cherish
 */
@Component
public class MQReceiver {

    @RabbitListener(queues = "MQ.LazyQueue")
    @RabbitHandler
    public void onLazyMessage(Message msg, Channel channel) throws IOException {
        long deliveryTag = msg.getMessageProperties().getDeliveryTag();
        // 手工确认
        channel.basicAck(deliveryTag, false);
        System.out.println("【lazy receive】： " + new String(msg.getBody()));
    }
}